package org.cinvestav.computacion.matias.onlyangel.grafo;


public class Grafo {
	public GrafoCelda grafo[][];
	public int size;
	public Grafo(Matriz arr){
		int y,x;
		size = arr.h*arr.w;
		grafo = new GrafoCelda[size][size];

		for (y=0;y<size;y++){
			for (x=0;x<size;x++){
				grafo[x][y] = new GrafoCelda();
			}
		}

		for (y=0;y<arr.h;y++){
			for (x=0;x<arr.w;x++){


				if ( (y-1>=0)&&(x-1>=0)){
					grafo[arr.arr[y][x].pos][arr.arr[y-1][x-1].pos].setVals(y-1, x-1, arr.arr[y-1][x-1].val);
				}

				if ((y-1>=0)){
					grafo[arr.arr[y][x].pos][arr.arr[y-1][x].pos].setVals(y-1, x, arr.arr[y-1][x].val);
				}

				if ((y-1>=0)&&(x+1<arr.w)){
					grafo[arr.arr[y][x].pos][arr.arr[y-1][x+1].pos].setVals(y-1, x+1, arr.arr[y-1][x+1].val);
				}

				if ((x-1>=0)){
					grafo[arr.arr[y][x].pos][arr.arr[y][x-1].pos].setVals(y, x-1, arr.arr[y][x-1].val);
				}

				if ((x+1<arr.w)){
					grafo[arr.arr[y][x].pos][arr.arr[y][x+1].pos].setVals(y, x+1, arr.arr[y][x+1].val);
				}

				if ((y+1<arr.h)&&(x-1>=0)){
					grafo[arr.arr[y][x].pos][arr.arr[y+1][x-1].pos].setVals(y+1, x-1, arr.arr[y+1][x-1].val);
				}

				if ((y+1<arr.h)){
					grafo[arr.arr[y][x].pos][arr.arr[y+1][x].pos].setVals(y+1, x, arr.arr[y+1][x].val);
				}

				if ((y+1<arr.h)&&(x+1<arr.w)){
					grafo[arr.arr[y][x].pos][arr.arr[y+1][x+1].pos].setVals(y+1, x+1, arr.arr[y+1][x+1].val);
				}
			}
		}
	}

	public void print(){
		int x, y;
		for (y=0;y<size;y++){
			for (x=0;x<size;x++){
				System.out.print(grafo[y][x].val+"\t");
			}
			System.out.println();
		}
	}
}
